
import React, { Component } from 'react'
import { connect } from 'dva';
import Link from 'umi/link';
import { Table, Divider, Modal, Drawer } from 'antd';
import Form from './components/RecordForm';
import { checkInit, dealElement } from '@/utils/util';

export interface Props {
  dispatch?: Function;
  children?: React.ReactNode;
  loading?: boolean;
  list?: {
    data: Array<any>;
    dataCnt: number;
  },
  buttons?: Array<any>;
  dict?: object;
}

@connect(({ device_alarm_other, loading, menu }) => ({
  list: device_alarm_other.list || {},
  dict: device_alarm_other.dict,
  buttons: menu.buttons,
  loading: loading.effects['device_alarm_other/queryPage']
}))
export default class Record extends Component<Props, any> {

  state = {
    current: 1,
  }

  initCurrent = () => {
    this.setState({
      current: 0
    })
  }

  queryData(pageSize) {

  }

  render() {

    const { data = [], dataCnt } = this.props.list;
    const ans = Array.isArray(data) ? data.map((it, index) => ({
      ...it,
      key: it.id,
    })) : []
    const pagination = {
      total: dataCnt,
      showTotal: total => `共 ${total} 条`,
      // showQuickJumper: true,
      // pageSize: ONE_PAGE_SIZE,
      onChange: (current) => {
        this.setState({ current });
        this.queryData(current)
      },
    };
    const columns = [
      {
        title: '报警时间',
        dataIndex: 'createTime',
      }, {
        title: '报警类型',
        dataIndex: 'deviceName',
      }, {
        title: '报警明细类型',
        dataIndex: 'stateName',
      }, {
        title: '报警状态',
        dataIndex: 'status',
      }, {
        title: '处理方式',
        dataIndex: 'handleType',
      }, {
        title: '处理人',
        dataIndex: 'handler',
      }, {
        title: '处理时间',
        dataIndex: 'handleTime',
      }];
    return (
      <>
        <Form current={this.state.current} initCurrent={this.initCurrent} />
        <Table
          columns={columns}
          pagination={pagination}
          dataSource={ans}
          bordered
          loading={this.props.loading}
        />
      </>
    )
  }
}